home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
comm2
/
ampop118.lha
/
AmiPOP118
/
source
/
pop_main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-13
|
10KB
|
539 lines
/* AmiPOP By Scott Ellis */
#include "pop.h"
UBYTE VersionID[]="$VER: AmiPOP "VERSION " "__AMIGADATE__ ;
/* Variables in pop.h */
char *pophost=NULL;
char *username=NULL;
char *password=NULL;
char *passfake=NULL;
char *mailbox=NULL;
char *cxname=NULL;
char *cxdesc=NULL;
char *hotkey=NULL;
char *title=NULL;
char *temp=NULL;
char *buf=NULL;
UBYTE *PubScreenName=NULL;
const char bum[]="Ok";
BOOL delmail=FALSE;
BOOL checkper=FALSE;
BOOL appfile=TRUE;
BOOL winop=TRUE;
BOOL notify=FALSE;
BOOL immediate=FALSE;
BOOL quiet=FALSE;
BOOL once=FALSE;
BOOL titlebar=FALSE;
int timecheck=10;
int port=110;
int winx=0;
int winy=0;
struct MsgPort *amipop_mp=NULL;
struct MsgPort *timer_mp=NULL;
struct timerequest *timerio=NULL;
CxObj *broker=NULL;
struct Library *TimerBase=NULL;
struct IntuitionBase *IntuitionBase=NULL;
struct Library *GadToolsBase=NULL;
struct NewBroker newbroker = {
NB_VERSION, /* nb_Version - Version of the NewBroker structure */
"Not Active", /* nb_Name */
VersionID + 6,/* nb_Title - Title of commodity that appears in CXExchange */
"Not Active", /* nb_Descr */
NBU_NOTIFY | NBU_UNIQUE , /* nb_Unique - Tells CX not to launch another commodity with same name */
COF_SHOW_HIDE, /* nb_Flags - Tells CX if this commodity has a window */
0, /* nb_Pri - This commodity's priority */
0, /* nb_Port - MsgPort CX talks to */
0 /* nb_ReservedChannel - reserved for later use */
};
struct EasyStruct ereq =
{
sizeof(struct EasyStruct),
0,
"AmiPOP Notice",
"%s",
"%s",
};
#ifndef OS30
UWORD __chip waitPointer[] =
{
0x0000, 0x0000, /* reserved, must be NULL */
0x0400, 0x07C0,
0x0000, 0x07C0,
0x0100, 0x0380,
0x0000, 0x07E0,
0x07C0, 0x1FF8,
0x1FF0, 0x3FEC,
0x3FF8, 0x7FDE,
0x3FF8, 0x7FBE,
0x7FFC, 0xFF7F,
0x7EFC, 0xFFFF,
0x7FFC, 0xFFFF,
0x3FF8, 0x7FFE,
0x3FF8, 0x7FFE,
0x1FF0, 0x3FFC,
0x07C0, 0x1FF8,
0x0000, 0x07E0,
0x0000, 0x0000, /* reserved, must be NULL */
};
#endif
enum args
{
USERNAME,
PASSWORD,
POPHOST,
MAILBOX,
CHECKPER,
TIME,
DELETE,
APPEND,
NOWINDOW,
PORT,
NOTIFY,
CX_POPKEY,
IMMEDIATE,
QUIET,
PUBSCREEN,
ONCE,
WINX,
WINY,
TITLEBAR
};
/* Configure SAS Specific routines */
void __regargs __chkabort(void) {}
long __stack = 20000;
/* End SAS */
/* Now define the structure that we will get when we start up the program */
typedef struct popstruct {
char pophost[BIGSTRING];
char username[SMALLSTRING];
char password[SMALLSTRING];
char passfake[SMALLSTRING];
char mailbox[BIGSTRING];
char cxname[BIGSTRING];
char cxdesc[3*BIGSTRING];
char hotkey[BIGSTRING];
char title[256];
char temp[BUFSIZE];
char buf[BUFSIZE];
char PubScreenName[SMALLSTRING];
} PopStruct;
ULONG sigmask=NULL;
ULONG cxsigflag=NULL;
ULONG timesigflag=NULL;
struct Library *IconBase;
struct RDArgs *RDA;
int main(int argc, char **argv)
{
int foo=0;
ULONG mysig;
#ifdef OS30
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39L);
#else
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37L);
#endif
GadToolsBase = OpenLibrary("gadtools.library",37L);
if (GadToolsBase && IntuitionBase)
{
if (makevars())
{
freevars();
return(20);
}
if ( parse(argc) )
{
if ( setuptime() )
{
timesigflag = 1L << timer_mp->mp_SigBit;
timereq();
foo=1;
if ( setupcx() )
{
if (winop)
{
openup();
}
}
else
{
foo=0;
}
}
}
else
{
foo=0;
}
if (once && foo)
{
MYGAD_BUTTONClicked();
foo=0;
}
if (immediate && foo) MYGAD_BUTTONClicked(); /* Check mail immediately */
while (foo)
{
if (winop)
{
sigmask= 1 << Project0Wnd->UserPort->mp_SigBit ;
}
else
{
sigmask= NULL;
}
mysig=Wait ( sigmask | cxsigflag | timesigflag | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_F);
if ( mysig & cxsigflag )
{
foo=docx();
}
if ( mysig & sigmask )
{
foo=HandleProject0IDCMP();
}
if ( mysig & timesigflag )
{
if (checkper)
{
MYGAD_BUTTONClicked();
}
timereq();
}
if ( mysig & SIGBREAKF_CTRL_C )
{
foo=0;
}
if ( mysig & SIGBREAKF_CTRL_F )
{
MYGAD_BUTTONClicked();
}
}
closedown();
closetime();
closecx();
freevars();
}
if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
if (GadToolsBase) CloseLibrary(GadToolsBase);
return(0);
}
void openup(void)
{
SetupScreen();
OpenProject0Window();
winop=TRUE;
}
void closedown(void)
{
CloseProject0Window();
CloseDownScreen();
winop=FALSE;
}
BOOL parse( int argc )
{
LONG *ArgumentArray; /* array for storing arguments retrieved by */
const char none[]="None Given";
if (!(ArgumentArray = ParseParameters(argc, "Username/K,Password/K,POPHost/K,MailBox/K,CheckPer/S,"
"Time/K/N,Delete/S,Append/S,NoWindow/S,Port/K/N,Notify/S,"
"Cx_Popkey/K,Immediate/S,Quiet/S,PubScreen/K,Once/S,"
"WinX/K/N,WinY/K/N,TitleBar/S")))
{
FreeParameters(ArgumentArray);
return(FALSE);
}
else
{
if (ArgumentArray[USERNAME])
{
strcpy(username,(char *)ArgumentArray[USERNAME]);
}
else
{
strcpy(username,none);
}
if (ArgumentArray[PASSWORD])
{
strcpy(password,(char *)ArgumentArray[PASSWORD]);
}
else
{
strcpy(password,"");
}
if (ArgumentArray[POPHOST])
{
strcpy(pophost,(char *)ArgumentArray[POPHOST]);
}
else
{
strcpy(pophost,none);
}
if (ArgumentArray[MAILBOX])
{
strcpy(mailbox,(char *)ArgumentArray[MAILBOX]);
}
else
{
strcpy(mailbox,none);
}
checkper=(BOOL)ArgumentArray[CHECKPER];
if (ArgumentArray[TIME])
{
timecheck=*(int *)ArgumentArray[TIME];
}
delmail=(BOOL)ArgumentArray[DELETE];
appfile=(BOOL)ArgumentArray[APPEND];
winop=!( (BOOL)ArgumentArray[NOWINDOW] );
if (ArgumentArray[PORT])
{
port = *(int *)ArgumentArray[PORT];
}
notify=(BOOL)ArgumentArray[NOTIFY];
if (ArgumentArray[CX_POPKEY])
{
strcpy(hotkey,(char *)ArgumentArray[CX_POPKEY]);
}
if (ArgumentArray[IMMEDIATE])
{
immediate=TRUE;
}
if (ArgumentArray[QUIET])
{
quiet=TRUE;
}
if (ArgumentArray[PUBSCREEN])
{
strcpy(PubScreenName,(UBYTE *)ArgumentArray[PUBSCREEN]);
}
if (ArgumentArray[ONCE])
{
once=TRUE;
}
if (ArgumentArray[WINX])
{
winx = *(int *)ArgumentArray[WINX];
}
if (ArgumentArray[WINY])
{
winy = *(int *)ArgumentArray[WINY];
}
if (ArgumentArray[TITLEBAR])
{
titlebar=TRUE;
}
FreeParameters(ArgumentArray);
return(TRUE);
}
}
LONG *ParseParameters(int argc, char *OriginalTemplate)
{
LONG *ArgumentArray; /* array for storing arguments retrieved by */
char **ToolArrayIndex, /* workbench tooltypes array */
*ToolStringIndex, /* index into string of concatenated workbench tooltypes */
*Template; /* readargs template - varies slightly for WB or CLI */
struct DiskObject *DiskObject; /* pointer to diskobject associated with program icon */
WORD ArgCount = 1; /* number of arguments in template */
RDA = AllocDosObjectTags(DOS_RDARGS, TAG_DONE);
RDA->RDA_ExtHelp = NULL;
Template = AllocVec(strlen(OriginalTemplate)+16,MEMF_CLEAR);
for ( ToolStringIndex = OriginalTemplate;
ToolStringIndex = strchr(ToolStringIndex,',');
ToolStringIndex++, ArgCount++);
ArgumentArray = AllocVec((ArgCount+1)*4,MEMF_CLEAR);
if (argc==0)
{
if (IconBase = OpenLibrary("icon.library", 36L) )
{
CurrentDir(_WBenchMsg->sm_ArgList->wa_Lock);
if (DiskObject = GetDiskObject(_WBenchMsg->sm_ArgList->wa_Name))
{
for ( ToolArrayIndex = DiskObject->do_ToolTypes;
*ToolArrayIndex;
ToolArrayIndex++)
{
RDA->RDA_Source.CS_Length += (strlen(*ToolArrayIndex)+1);
}
if (RDA->RDA_Source.CS_Length)
{
RDA->RDA_Source.CS_Buffer = AllocVec(RDA->RDA_Source.CS_Length+1,MEMF_CLEAR);
ToolStringIndex = RDA->RDA_Source.CS_Buffer;
for ( ToolArrayIndex = DiskObject->do_ToolTypes;
*ToolArrayIndex;
ToolArrayIndex++)
{
ToolStringIndex = stpcpy(stpcpy(ToolStringIndex,*ToolArrayIndex)," ");
}
*(ToolStringIndex-1) = '\n';
FreeDiskObject(DiskObject);
}
}
}
stpcpy(stpcpy(Template,OriginalTemplate),",ThrowAway/M");
}
else
{
strcpy(Template,OriginalTemplate);
}
RDA = ReadArgs(Template,ArgumentArray,RDA);
FreeVec(Template);
if (RDA)
{
return(ArgumentArray);
}
else
{
return(NULL);
}
}
void FreeParameters(LONG *ArgumentArray)
{
if (RDA)
{
if ((RDA->RDA_Source.CS_Length) && (RDA->RDA_Source.CS_Buffer))
{
FreeVec(RDA->RDA_Source.CS_Buffer);
}
FreeArgs(RDA);
FreeDosObject(DOS_RDARGS,RDA);
}
else
{
PrintFault(IoErr(), NULL);
}
if (ArgumentArray)
{
FreeVec(ArgumentArray);
}
}
int doreq( const char *mes, const char *but)
{
LONG answer;
if ( !quiet )
{
answer= EasyRequest(NULL, &ereq, NULL, mes, but);
if (Project0Wnd)
{
SetWindowTitles(Project0Wnd,Project0Wdt, (UBYTE *) ~0);
}
return(answer);
}
}
BOOL makevars(void)
{
PopStruct *blockptr;
if ( blockptr=AllocVec(sizeof(PopStruct),MEMF_CLEAR) )
{
pophost=blockptr->pophost;
username=blockptr->username;
password=blockptr->password;
passfake=blockptr->passfake;
mailbox=blockptr->mailbox;
cxname=blockptr->cxname;
cxdesc=blockptr->cxdesc;
hotkey=blockptr->hotkey;
title=blockptr->title;
temp=blockptr->temp;
buf=blockptr->buf;
PubScreenName=blockptr->PubScreenName;
return(FALSE);
}
return(TRUE);
}
void freevars(void)
{
if (pophost) FreeVec(pophost);
}